package com.kafka.spring_demo_01;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@SpringBootApplication
@RequestMapping
public class SpringDemo01Application {
	private static final Logger logger = LoggerFactory.getLogger(SpringDemo01Application.class);

	public static void main(String[] args) {
		SpringApplication.run(SpringDemo01Application.class, args);
	}

	@RequestMapping("/index")
	public String index(){
		return "hello,kafka";
	}

	@Autowired
	private KafkaTemplate template;
	private static final String topic = "heima-01";

	/**
	 * 消息生产者
	 * @param input
	 * @return
	 */
	@GetMapping("/send/{input}")
	public String sendToKafka(@PathVariable("input") String input){
		this.template.send(topic,input);
		return "send success";
	}

	/**
	 * 消息消费者
	 * @param input
	 */
	@KafkaListener(id="",topics= topic,groupId = "groupA")
	public void listener(String input){
		logger.info("message input value:{}",input);
	}



}

